#pragma once
#include <vector>
#include<string.h>
#include <sys/epoll.h>
#include <unistd.h>
#include"Poller.h"
#include"log.h"
#include"Channel.h"
const int Knew = -1;
const int Kadded = 1;
const int Kdelete = 2;

// #pragma once

// #include "Poller.h"
// #include "TimeStamp.h"

// #include <vector>
// #include <sys/epoll.h>

class Channel;

class EpollPoller : public Poller
{
public:
    EpollPoller(EventLoop *loop);
    ~EpollPoller();
    // 输出型参数输出活跃事件。
    TimeStamp poll(int timeoutMs, ChannelList *activeChannels);

    void updateChannel(Channel *channel);

    // 从poller中删除channel
    void removeChannel(Channel *channel);

private:
    static const int KInitEventListSize_ = 16;
    using EventList = std::vector<epoll_event>;
    // 填写活跃的链接
    void fillActiveChannel(int numEvents, ChannelList *activeChannels) const;

    // 更新channel通道
    void update(int operation, Channel *channel);

    int epollfd_;
    EventList events_; // 存储发生事件的fd
};